    //最原始数据字符串，从android获得
    var customerDataJSONStr;

    //把原始数据转化为JSONObj
    var customerDataJSONObj;
    var userName;

    //所有天的原始数据
    var customerDataJSONArray;
    var customerDataJSONArrayLen;

    var customerDate;
	var customerPeriod;
	var customerTemperature;
	var heart;
	var moon;
	var medicine;
	var drink;
	var plane;
	var mucus;

	var customerDateStr;
	var customerDateTemperatureStr;
	var customerDatePolishedTemperatureStr;

	var customerDatePeriodStr;
	var customerDateHeartStr;
	var customerDateMoonStr;
	var customerDateMedicineStr;
	var customerDateDrinkStr;
	var customerDatePlaneStr;
	var customerDateMucusStr;

    var customerDateTemperatureMap = new Map();
    var customerDateLimitedTemperatureMap = new Map();
    var customerDatePolishedTemperatureMap = new Map();

    var customerDateMucusMap = new Map();
    var customerDatePeriodMap = new Map();

    var customerDateArray = new Array();

    /*
	    1) customerTemperatureArray是客户的真实数据。
	    2) customerDateLimitedTemperatureArray是把真实数据全部过滤一遍，把所有真实限制在
	       getMinTemperature() - getMaxTemperature() 度之间的数据。
	       如果超过此范围则让其 = min 或 max 度，其目的就是为了画图时不超出上下区域。
	    3) customerDatePolishedTemperatureArray是为了能够断点连线画图，补齐中间空白的数据，
	       其输入根据是customerDateLimitedTemperatureArray。
	*/

    var customerTemperatureArray = new Array();
    var customerDateLimitedTemperatureArray = new Array();
    var customerDatePolishedTemperatureArray = new Array();

    //为了画出充满grid的曲线图，去掉两头可能存在的空白值
    var firstValidTemperatureDate;
    var customerValidDateArray = new Array();
    var customerValidTemperatureArray = new Array();

 var validBBTNum = 0;
 var atualShowPeriodNum;
 var validMucusNum = 0;

  function initData(){

    window.CustomerData.printJS("I am in initData.js --> initData()!");

    initCustomerDataIntoJSON();
    initCustomerDataIntoArrayMap();

    clearLocalCustomerDateData();
    saveCustomerDateDataStr2Local();

    initOverviewChartData();
    saveOverviewChartData();

    window.CustomerData.sendCurveMsg();
  }

  //为了splash时不用再次调用, 暂时不用
  //由于每次登陆时都重新initData，所以切换用户时不会使用上次用户的storage数据
  function hasUserData(){
    customerDataJSONStr = window.CustomerData.getCustomerDataJSONStr();
    customerDataJSONObj = JSON.parse(customerDataJSONStr);

    userName = customerDataJSONObj.userName;

    return userName == localStorage.getItem("userName");
  }

  function initCustomerDataIntoJSON(){
    customerDataJSONStr = window.CustomerData.getCustomerDataJSONStr();
    customerDataJSONObj = JSON.parse(customerDataJSONStr);

  	customerDataJSONArray = customerDataJSONObj.customerDataJSONArray;
  	customerDataJSONArrayLen = customerDataJSONArray.length;
  }

  function initCustomerDataIntoArrayMap(){
  	for(var i = 0; i < customerDataJSONArrayLen; i ++){
  		getJSONArrayCustomerDateData(i);

  		customerDateArray[i] = customerDate;
    	customerTemperatureArray[i] = customerTemperature;
  		customerDateTemperatureMap.put(customerDate, customerTemperature);

  		if(customerTemperature < getMinTemperatureC())
  		    customerDateLimitedTemperatureArray[i] = getMinTemperatureC();
  		else if (customerTemperature > getMaxTemperatureC())
  		    customerDateLimitedTemperatureArray[i] = getMaxTemperatureC();
  		else
  		    customerDateLimitedTemperatureArray[i] = customerTemperature;

  		customerDateLimitedTemperatureMap.put(customerDate, customerDateLimitedTemperatureArray[i]);

        customerDatePeriodMap.put(customerDate, customerPeriod);
        customerDateMucusMap.put(customerDate, mucus);
  	}

  	initCustomerDatePolishedTemperatureArray();
  	initCustomerDatePolishedTemperatureMap();
  }

  function initCustomerDatePolishedTemperatureArray(){
    initFirstValidTemperatureDate();

    if(firstValidTemperatureDate == "-"){//没有任何数据
    	customerDatePolishedTemperatureArray = customerTemperatureArray;
    }else{
        for(var i = 0; i< customerDataJSONArrayLen; i++){
            if(needPolish(i)){
                var previousValidDateStr =  getPreviousValidBBTDate(i, customerDateArray.toString());
                var nextValidDateStr = getNextValidBBTDate(i, customerDateArray.toString());

                if(previousValidDateStr == "-" || nextValidDateStr == "-"){
                    customerDatePolishedTemperatureArray[i] = "-";
                }
                else{
                    customerDatePolishedTemperatureArray[i] = getPolishedTemperature(previousValidDateStr, customerDateArray[i], nextValidDateStr);
                }

            }else{
                customerDatePolishedTemperatureArray[i] = customerDateLimitedTemperatureArray[i];
            }
        }
    }

  }

  function needPolish(i){
  	return customerTemperatureArray[i] == "-" &&
                        compareDateStr(customerDateArray[i],getCurrentDateStr()) &&
                        compareDateStr(firstValidTemperatureDate, customerDateArray[i]);

  }

  function initCustomerDatePolishedTemperatureMap(){
  	for(var i = 0; i < customerDataJSONArrayLen; i ++){
  		var customerDate = customerDataJSONArray[i].date;
  		customerDatePolishedTemperatureMap.put(customerDate, customerDatePolishedTemperatureArray[i]);
  	}
  }

  function clearLocalCustomerDateData(){
  	localStorage.clear();
  }

  function saveCustomerDateDataStr2Local(){
  	customerDateStr = "[";
  	customerDateTemperatureStr = "[";
  	customerDatePolishedTemperatureStr = "[";
	customerDatePeriodStr = "[";
	customerDateHeartStr = "[";
	customerDateMoonStr = "[";
	customerDateMedicineStr = "[";
	customerDateDrinkStr = "[";
	customerDatePlaneStr = "[";
	customerDateMucusStr = "[";

  	for(var i = 0; i < customerDataJSONArrayLen; i ++){
		getJSONArrayCustomerDateData(i);

  		customerDateStr += '{"date":"'+ customerDate + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateStr += ",";

  		customerDateTemperatureStr += '{"date":"'+ customerDate + '", "temperature":"' + customerTemperature + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateTemperatureStr += ",";

  		customerDatePolishedTemperatureStr += '{"date":"'+ customerDate + '", "temperature":"' + customerDatePolishedTemperatureArray[i] + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDatePolishedTemperatureStr += ",";

  		customerDatePeriodStr += '{"date":"'+ customerDate + '", "period":"' + customerPeriod + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDatePeriodStr += ",";

  		customerDateHeartStr += '{"date":"'+ customerDate + '", "heart":"' + heart + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateHeartStr += ",";

  		customerDateMoonStr += '{"date":"'+ customerDate + '", "moon":"' + moon + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateMoonStr += ",";

  		customerDateMedicineStr += '{"date":"'+ customerDate + '", "medicine":"' + medicine + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateMedicineStr += ",";

  		customerDateDrinkStr += '{"date":"'+ customerDate + '", "drink":"' + drink + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateDrinkStr += ",";

  		customerDatePlaneStr += '{"date":"'+ customerDate + '", "plane":"' + plane + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDatePlaneStr += ",";

  		customerDateMucusStr += '{"date":"'+ customerDate + '", "mucus":"' + mucus + '"}';
  		if( i != customerDataJSONArrayLen - 1)
  			customerDateMucusStr += ",";
  		if(mucus != "0")
  			validMucusNum ++;
  	}

  	customerDateStr += "]";
  	customerDateTemperatureStr += "]";
  	customerDatePolishedTemperatureStr += "]";
  	customerDatePeriodStr += "]";
  	customerDateHeartStr += "]";
  	customerDateMoonStr += "]";
  	customerDateMedicineStr += "]";
  	customerDateDrinkStr += "]";
  	customerDatePlaneStr += "]";
  	customerDateMucusStr += "]";

  	saveCustomerData2Local("customerDateKey", customerDateStr);
  	saveCustomerData2Local("customerDateTemperatureKey", customerDateTemperatureStr);
  	saveCustomerData2Local("customerDatePolishedTemperatureKey", customerDatePolishedTemperatureStr);
  	saveCustomerData2Local("customerDatePeriodKey", customerDatePeriodStr);
  	saveCustomerData2Local("customerDateHeartKey", customerDateHeartStr);
  	saveCustomerData2Local("customerDateMoonKey", customerDateMoonStr);
  	saveCustomerData2Local("customerDateMedicineKey", customerDateMedicineStr);
  	saveCustomerData2Local("customerDateDrinkKey", customerDateDrinkStr);
  	saveCustomerData2Local("customerDatePlaneKey", customerDatePlaneStr);
  	saveCustomerData2Local("customerDateMucusKey", customerDateMucusStr);
  	saveCustomerData2Local("customerDateDataStrKey", JSON.stringify(customerDataJSONArray));
  	saveCustomerData2Local("customerDataJSONArrayLenKey", customerDataJSONArrayLen);
  	saveCustomerData2Local("validMucusNumKey", validMucusNum);

  	saveCustomerData2Local("userName", userName);

  	var language = customerDataJSONObj.language;
    saveCustomerData2Local("language", language);

    var unit = customerDataJSONObj.unit;
    saveCustomerData2Local("unit", unit);

    var state = customerDataJSONObj.state;
    saveCustomerData2Local("state", state);
  }

  function getJSONArrayCustomerDateData(i){
  		customerDate = customerDataJSONArray[i].date;
		customerPeriod = customerDataJSONArray[i].period;
  		customerTemperature = customerDataJSONArray[i].temperature;
  		heart = customerDataJSONArray[i].heart;
  		moon = customerDataJSONArray[i].moon;
  		medicine = customerDataJSONArray[i].medicine;
  		drink = customerDataJSONArray[i].drink;
  		plane = customerDataJSONArray[i].plane;
  		mucus = customerDataJSONArray[i].mucus;
  }

  function saveCustomerData2Local(key, value){
   	localStorage.setItem(key, value);
  }